package cn.kgc.ssm.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * @author: mosin
 * @version: v1.0  2022/10/21
 * 监听application域对象的创建
 */
@WebListener
public class MyContextListener implements ServletContextListener {

    // 全局域对象的创建
    @Override
    public void contextInitialized(ServletContextEvent sce) {

        // 获取项目的虚拟路径
        String contextPath = sce.getServletContext().getContextPath();
        sce.getServletContext().setAttribute("bp", contextPath);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}
